var Chat= function (socket) {
    this.socket=socket;
};

//发送聊天消息
Chat.prototype.sendMsg= function (room, text) {
    var msg={
        room:room,
        text:text
    };
    this.socket.emit('message',msg);
}

//变更房间
Chat.prototype.changeRoom= function (room) {
    this.socket.emit('join',{
       newRoom:room
    });
}

//聊天命令
Chat.prototype.processCmd= function (cmd) {
    var words=command.split(' ');
    var cmd=words[0].substring(1,words[0].length).toLowercase();
    var msg=false;
    switch(cmd){
        case 'join':
            words.shift();
            var room = words.join(' ');
            this.changeRoom(room);
            break;

        case 'nick':
            words.shift();
            var name=words.join(' ');
            this.socket.emit('nameAttempt',name);
            break;

        default:
            msg='Unrecognized cmd.';
            break;
    }
    return msg;
}


